package jman.teemwork10;

import java.sql.SQLException;

public class Manager {
	public boolean registered(String name,String password){
		boolean result=false;
		User user=new User(name,password);
		DatebaseManager dm=new DatebaseManager();
		dm.getCon();
		dm.read(user);
		try {
			if(dm.getRs().next()){
				System.out.println("注册失败");
			}else{
				dm.add(user);
				System.out.println("注册成功");
				result=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("注册失败");
		}
		dm.closeRs();
		dm.closePs();
		dm.closeCon();
		return result;
	}
	public boolean login(String name,String password){
		boolean result=false;
		User user=new User(name,password);
		DatebaseManager dm=new DatebaseManager();
		dm.getCon();
		dm.read(user);
		try {
			if(dm.getRs().next()){
				try {
					if(dm.getRs().getString("pwd").equals(password)){
						result=true;
						System.out.println("登录成功");
					}else{
						System.out.println("登录失败");
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					System.out.println("登录失败");
				}
			}else{
				System.out.println("登录失败");
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			System.out.println("登录失败");
		}
		dm.closeRs();
		dm.closePs();
		dm.closeCon();
		return result;
	}
}
